< previous page page_220 next page >

Page 220
function would expect to see the actual message, rasconnstate, and dwError values on the stack, since these parameters are not pointers. That means you would use ByVal in the declaration for all of these parameters.
Public Declare RasDialFunc Lib "some library" (ByVal unMsg As Long, _
ByVal rasconnstate As Long, ByVal dwError As Long) As Long
The C function declaration shows the function return a void, which is equivalent to no return value. You could use a Sub instead of Function declaration at this point, but it is just as valid to remain consistent and use a function declaration that returns a Long value. Just ignore the result.
How would you define a public function in a standard module so that it would take the value from the stack? In exactly the same way. The function needs to be defined as follows:
Public Function RasFunc(ByVal unMsg As Long, ByVal RasConnState As _
Long, ByVal dwError As Long) As Long
Does this mean all you need to do with a callback function is create a Declare statement and change it into a regular function? As long as you are dealing with numeric variables, yes. But this approach falls apart with strings and structures. API functions that use callbacks will pass strings or structures as pointers to a string or structure. You should define your callback function parameter ByVal As Long and interpret the variable you receive as a pointer. You can then copy the data to a local string or structure using the lstrcpy or RtlMoveMemory functions.

 
< previous page page_220 next page >